//----BEGIN implement for paging----------//
// ThanhTX add 2007.06.15
// ThanhTX udpate 2007.06.19
// ThanhTX update  isYuubinbangou 2007.06.20
function checkBlank(objCheck,strName){
	var strMsgInput = "Khong Duoc Rong";
	if(isWhitespace(objCheck.value)){
		alert(strName+strMsgInput);
		objCheck.focus();
		return false;
	}
	return true;
}	
function CheckPhone(s)
{
  var str ="0123456789().- ";
  for (var j=0;j<s.length;j++)
  	if(str.indexOf(s.charAt(j))==-1)
	return false;
  return true;
}
function SearchGotoPage(oForm){
	try {
		var url= oForm.action ;
		//alert( url);
		var aParams = smc_GetRequestOfForm(oForm);
		//alert ("submitForm AA" + aParams);
		smc_XmlHttpSend(url,"POST",aParams,"showResultSearch",true);
		
	} catch (e) {
		alert(e.description);
	}
	return false;
}

function GotoPage(iPage){
	document.frmProduct.action =document.frmProduct.action  + "&curPg="+iPage;
	//alert(document.frmProduct.action);
	SearchGotoPage(document.frmProduct);
}

//set value--

function getValueById(id){
	return getById(id).value;	
}
function setValueById(id,value){
	getById(id).value = value;	
}
function getInnerById(id){
	return getById(id).innerHTML;	
}
function setInnerById(id,value){
	getById(id).innerHTML = value;	
}

function getElement(e,f){
    if(document.layers){
        f=(f)?f:self;
        if(f.document.layers[e]) {
            return f.document.layers[e];
        }
        for(W=0;i<f.document.layers.length;W++) {
            return(getElement(e,fdocument.layers[W]));
        }
    }
    if(document.all) {
        return document.all[e];
    }
    return document.getElementById(e);
}


function getById(id){
	return document.getElementById(id);	
    if(document.layers){
        f= self;
        if(f.document.layers[id]) {
            return f.document.layers[id];
        }
        for(var W=0;i<f.document.layers.length;W++) {
            return(getElement(id,f.document.layers[W]));
        }
    }
    if(document.all) {
        return document.all[id];
    }
    return document.getElementById(id);
	// Can update de chay voi moi trinh duyet
	//return document.getElementById(id);	
}



function getSearch(str,id_loai,perent_id)
{
	//alert(perent_id);
	if (str.length==0)
	  {
	  document.getElementById("sortdiv").innerHTML="";
	  //document.getElementById("sortdiv").style.border="0px";
	  return;
	  }
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	 
	xmlhttp.onreadystatechange=function()
  	{
		 if (xmlhttp.readyState == 4) {
			// only if "OK"
			if (xmlhttp.status == 200) {						
				document.getElementById('sortdiv').innerHTML=xmlhttp.responseText;				
				document.getElementById("sortList2").value = str;
			} else {
				alert("There was a problem while using XMLHTTP:\n" + xmlhttp.statusText);
			}
		}				
	 
 	 }
	 
	xmlhttp.open("GET","../view/getsort.php?id_loai_sp="+id_loai+"&perent_id="+perent_id+"&sort="+str,true);	
	xmlhttp.send();
}

function getSearchNew(str)
{
	//alert(perent_id);
	if (str.length==0)
	  {
	  document.getElementById("sortdivlistnew").innerHTML="";
	  //document.getElementById("sortdiv").style.border="0px";
	  return;
	  }
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	 
	xmlhttp.onreadystatechange=function()
  	{
		 if (xmlhttp.readyState == 4) {
			// only if "OK"
			if (xmlhttp.status == 200) {						
				document.getElementById('sortdivlistnew').innerHTML=xmlhttp.responseText;				
				document.getElementById("sortList2").value = str;
			} else {
				alert("There was a problem while using XMLHTTP:\n" + xmlhttp.statusText);
			}
		}				
	 
 	 }
	 
	xmlhttp.open("GET","../view/getsortnew.php?sort="+str,true);	
	xmlhttp.send();
}
//function kiem tra mail
//document.charset='shift_jis';
function isEmail(s)
{   
//Neu mail la chuoi rong
  if (s=="") return false;
  //Neu mail la chuoi co khoang trang
  if(s.indexOf(" ")>0) return false;
  //Neu mail la chuoi khong co dau @
  if(s.indexOf("@")==-1) return false;
  var i = 1;
  var sLength = s.length;
  //Neu mai la chuoi khong co dau cham
  if (s.indexOf(".")==-1) return false;
  //Neu mail la chuoi co 2 dau . gan nhau
  if (s.indexOf("..")!=-1) return false;
  //Neu mail la chuoi co 2 dau .@
  if (s.indexOf(".@")!=-1) return false;
  //Neu mai la chuoi co 2 dau @
  if (s.indexOf("@")!=s.lastIndexOf("@")) return false;
  //Neu mail la chuoi co dau . cuoi cung
  if (s.lastIndexOf(".")==s.length-1) return false;
  //Neu mail la chuoi ky tu khong thuoc chuoi ky tu sau
  var str="0123456789abcdefghikjlmnopqrstuvwxyzABCDEFGHIKJLMNOPQRSTUVWXYZ-@._"; 
  for(var j=0;j<s.length;j++)
	if(str.indexOf(s.charAt(j))==-1)
		return false;
	//Neu mai la chuoi hop le phuong thuc tra ve true
   return true;
}
// ThanhTX add 2007.06.19
function isDenwabangou(s)
{   
	if(isNaN(s)) return false;
	if( ! isNubers(s) ) return false;	
	if(s.length<7) return false;
	if(s.length > 11) return false;
	if (parseInt(s,0)==0)  return false;
   	return true;
}



function isYuubinbangoo1(s)
{   
	if(s.length<3) return false;
	if (s+1==1)  return false;
	return isNubers(s);
}

function isYuubinbangoo2(s)
{   
	if(s.length<4) return false;
	if (s+1==1)  return false;
	return isNubers(s);   
}


function isEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}


function isWhitespace (s)
{   
	var whitespace = " \t\n\r";
	var i;

  if (isEmpty(s)) return true;
  for (i = 0; i < s.length; i++)
  {   
    var c = s.charAt(i);
    if (whitespace.indexOf(c) == -1) return false;
  }
  return true;
}
function isNuber(c)
{
	return (c>="0" && c<="9");
}
function isNubers(str)
{
	var isOK=true;
	for(var i=0;i<str.length;i++)
	{
		if(! isNuber(str.charAt(i)))
			{
				isOK=false;
				break;
			}
	}
	return isOK;	
}

function isNumbers(str)
{
	//alert("isNumbers" +str.length );
	var isOK=true;
	for(var i=0;i < str.length;i++)
	{
		//alert(i);
		var c =str.charAt(i)
		//alert(c);
		if(!isNuber(c))
			{
				//alert("false");
				isOK=false;
				break;
			}
	}
	return isOK;	
}

//===========================================================
//***********************************************************
//
// defines
// width to resize large images to
// Su dung thay doi kich thuoc anh
var maxWidth=200;
  // height to resize large images to
var maxHeight=250;
  // the id of the preview image tag
var outImage="previewField";

function choseImage(strImage)
{
  var source=strImage;
  //alert("strImage=" + strImage);
  globalPic=new Image();
  globalPic.src=source;

  setTimeout("applyChanges()",200);
}

var globalPic;
function applyChanges()
{
  var field=document.getElementById(outImage);
  var x=parseInt(globalPic.width);
  var y=parseInt(globalPic.height);
  if (x>maxWidth)
  {
    y*=maxWidth/x;
    x=maxWidth;
  }

  if (y>maxHeight)
  {
    x*=maxHeight/y;
    y=maxHeight;
  }
  field.style.display=(x<1 || y<1)?"none":"";
  field.src=globalPic.src;
  field.width=x;
  field.height=y;
}
//*************************************************************//

/**
  * Checks/unchecks all options of a <select> element
  *
  * @param   string   the form name
  * @param   string   the element name
  * @param   boolean  whether to check or to uncheck the element
  *
  * @return  boolean  always true
  */
function setSelectOptions(formName, selectName, valueSelectName)
{
    var selectObject = document.forms[formName].elements[selectName];
	var valueSelect  = document.forms[formName].elements[valueSelectName].value;
	if(valueSelect =="") return;
	document.forms[formName].elements[valueSelectName].value ="";
	
    var selectCount  = selectObject.length;
    for (var i = 0; i < selectCount; i++) {
        if(selectObject.options[i].value == valueSelect){
			selectObject.options[i].selected = true;
			 return true;
		}
    } // end for

    return true;
} // end of the 'setSelectOptions()' function

function getOptionsValue(objOption){
	//var objOption = document.forms[formName].elements[optionName];
	//var objOption = document.forms[formName].elements[optionName];
	for (i = 0; i <objOption.length; i++){
		
		if(objOption[i].checked==true){
			objOption.value = objOption[i].value
			return objOption[i].value;
		}
	}
	return "";
}

function getCheckBoxManyValue(objCheckBox){
	//var objOption = document.forms[formName].elements[optionName];
	//var objOption = document.forms[formName].elements[optionName];
	var values ="";
	for (i = 0; i <objCheckBox.length; i++){		
		if(objCheckBox[i].checked==true){
			if(values !="") values += ("," + objCheckBox[i].value);
			else values = objCheckBox[i].value;
		}
	}
	//objCheckBox.value = values;
	return values;
}

/**
  * listbox redirection
  */
function goToUrl(selObj, goToLocation){
    eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
}

/**
 * getElement
 */
function getElement(e,f){
    if(document.layers){
        f=(f)?f:self;
        if(f.document.layers[e]) {
            return f.document.layers[e];
        }
        for(W=0;i<f.document.layers.length;W++) {
            return(getElement(e,fdocument.layers[W]));
        }
    }
    if(document.all) {
        return document.all[e];
    }
    return document.getElementById(e);
}

// ThanhTX update  isYuubinbangou 2007.06.20

function isYuubinbangou(s)
{   
	//alert("isYuubinbangou");
	//return true;
	if(s.length <7) return false;
	if (parseInt(s,0)==0) return false;
	var strTmp = s.substr(0,3) + s.substr(4,s.length-1);
	//alert(strTmp);
	if( ! isNumbers(strTmp) ) return false;	
	//if ( strTmp==0)  return false;
	//if(! isNubers(strTmp)) return false;   
	return true;
}


// Create Oanhhtk
function showDialog(url, width, height)
{
	return showWindow(url, false, false, false, false, false, false, true, true, width, height, 0, 0);
}

function showWindow(url, isStatus, isResizeable, isScrollbars, isToolbar, isLocation, isFullscreen, isTitlebar, isCentered, width, height, top, left)
{
	if (isCentered)
	{
		top = (screen.height - height) / 2;
		left = (screen.width - width) / 2;
	}

	open(url, '_blank', 'status=' + (isStatus ? 'yes' : 'no') + ','
	+ 'resizable=' + (isResizeable ? 'yes' : 'no') + ','
	+ 'scrollbars=' + (isScrollbars ? 'yes' : 'no') + ','
	+ 'toolbar=' + (isToolbar ? 'yes' : 'no') + ','
	+ 'location=' + (isLocation ? 'yes' : 'no') + ','
	+ 'fullscreen=' + (isFullscreen ? 'yes' : 'no') + ','
	+ 'titlebar=' + (isTitlebar ? 'yes' : 'no') + ','
	+ 'height=' + height + ',' + 'width=' + width + ','
	+ 'top=' + top + ',' + 'left=' + left);
}
function displayInfo(info)
{
	if (info == 'weather')
		showDialog('http://www3.tuoitre.com.vn/Transweb/Weather.aspx', 550, 560);
	if (info == 'forex')	
	    showDialog('http://www.tuoitre.com.vn/tianyon/transweb/TyGia.htm', 305, 415);
	    //showDialog('http://www.eximbank.com.vn/vietnam/exchange.aspx', 460, 432);
		//showDialog('http://www3.tuoitre.com.vn/transweb/tygia.htm', 460, 432);
	if (info == 'gold')
		showDialog('http://www3.tuoitre.com.vn/transweb/giavang.htm', 450, 220);
	if (info == 'tvguide')
		showWindow('http://www3.tuoitre.com.vn/transweb/truyenhinh.htm', false, false, true, false, false, false, true, true, 450, 354, 0, 0);
	if (info == 'lottery')	
	    showDialog('http://www.xosothudo.com.vn/xemkqtt.asp', 800, 510);
	    //showWindow('http://www.xosobinhduong.com.vn/Forms/xemkq_tt.aspx', false, false, true, false, false, false, true, true, 450, 600, 0, 0);
		//showWindow('http://www3.tuoitre.com.vn/Transweb/XoSo.html', false, false, true, false, false, false, true, true, 450, 600, 0, 0);
		//showDialog('http://www3.tuoitre.com.vn/transweb/xoso.htm', 600, 346);
		//showDialog('http://www.xsktcantho.com.vn/xsktcantho.asp', 1024, 1350);
	if (info == 'stock_ho')
		showWindow('http://www3.tuoitre.com.vn/transweb/chungkhoan_ho.htm', false, false, true, false, false, false, true, true, 770, 770);
	if (info == 'stock_ha')
		showWindow('http://www3.tuoitre.com.vn/transweb/chungkhoan_ha.htm', false, false, true, false, false, false, true, true, 770, 770);	
}

